package com.example.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.Activity.R;
import com.example.adapter.FruitAdapter1;
import com.example.entity.Fruit;

import java.util.ArrayList;
import java.util.List;


public class VideoFragment extends Fragment {
    View view;
    private List<Fruit> fruitList = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.video_fragment,container,false);
        initFruits();
        RecyclerView recyclerView = view.findViewById(R.id.recycler_view1);
        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(),2);
//        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        FruitAdapter1 adapter1 = new FruitAdapter1(fruitList);
        recyclerView.setAdapter(adapter1);

        return view;
    }

    private void initFruits() {
        Fruit pear = new Fruit("雪糕", R.drawable.ms_1);
        fruitList.add(pear);
        Fruit strawberry = new Fruit("糖醋排骨", R.drawable.ms_2);
        fruitList.add(strawberry);
        Fruit watermelon = new Fruit("美味鸡翅", R.drawable.ms_3);
        fruitList.add(watermelon);
        Fruit grange = new Fruit("麻辣小龙虾", R.drawable.ms_4);
        fruitList.add(grange);
        Fruit grape = new Fruit("大闸蟹", R.drawable.ms_5);
        fruitList.add(grape);
        Fruit iango = new Fruit("麻婆豆腐", R.drawable.ms_6);
        fruitList.add(iango);
    }
}
